using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerHurtDownState : PlayerGlobalState
{
    public PlayerHurtDownState(Player player, PlayerMoveData playerData, StateMachine stateMachine, string animName) : base(player, playerData, stateMachine, animName)
    {
    }

    private bool isDown;

    private float hurtValue;

    public void SetHurtValue(float hurtValue) { this.hurtValue = hurtValue; }

    public override void Enter()
    {
        base.Enter();

        isDown = false;
    }

    public override void LogicUpdate()
    {
        base.LogicUpdate();

        if (isDown)
        {
            player.SetVelocityX(0);
            player.animator.Play("HurtUp");
            if (isAnimationFinish)
            {
                if (player.Health.IsDead)
                {
                    stateMachine.ChangeState(player.DeadState);
                }
                else 
                {
                    stateMachine.ChangeState(player.IdleState);
                } 
            }
        }
        else 
        {
            player.SetVelocityX(hurtValue);
        }
    }

    public override void OnAnimationTrigger()
    {
        base.OnAnimationTrigger();

        isDown = true;
    }
}
